

**************************************************************
**************** Baseline Results (Figure 1) *****************
**************************************************************

clear 
set more off

use "${path}\Clean Data\CPS Final.dta"

drop if OCC == .

rename WeeklyLaborIncome WLI
rename RealWage RW
rename Emp EMP
rename UnEmp Output

sort OCC time

xtset OCC time

* Decide to use original shocks, or shocks estimated with GARCH
drop RR
rename resid_garch RR

egen t = min(time)

gen time2 = time*time

replace Output = log(Output)
replace RW = log(RW)
replace WLI = log(WLI)
gen Emp = log(emp)
gen hours = log(Hours)

*gen Output = INDPRO

*********************
* Define local macros
*********************

* 12 months of lags
local MaxLPLags 12

* 3 year horizon
local horizon 36

* Romer and Romer shocks 
local policy RR

* O is the number of occupation subgroups under consideration
local o 3

***** LHS variable: the response variable

forvalues i=0/`horizon' {
	
	gen RW`i'    = f`i'.RW - l1.RW
	gen WLI`i'   = f`i'.WLI - l1.WLI
	gen Emp`i'   = f`i'.Emp - l1.Emp
	gen hours`i' = f`i'.hours-l1.hours
	gen Output`i' = f`i'.Output-l1.Output
	
}

forvalues v = 1/`o' {
gen b_`v'WLI=.
gen b_`v'RW=.
gen b_`v'Emp=.
gen b_`v'hours=.


gen se_`v'WLI=.
gen se_`v'RW=.
gen se_`v'Emp=.
gen se_`v'hours=.

}

gen b_Output=.
gen se_Output=.


** Controls in LP regression **

local rhsWeeklyLaborIncome l(1/`MaxLPLags').FF l(1/`MaxLPLags').WLI time time2
*l(1/`MaxLPLags').logIP l(1/`MaxLPLags').logCPI 
						
local rhsRealWage l(1/`MaxLPLags').FF l(1/`MaxLPLags').RW time time2
*l(1/`MaxLPLags').logIP l(1/`MaxLPLags').logCPI 
					
local rhsEmp l(1/`MaxLPLags').FF l(1/`MaxLPLags').Emp time time2
*l(1/`MaxLPLags').logIP l(1/`MaxLPLags').logCPI 
	
local rhshours l(1/`MaxLPLags').FF l(1/`MaxLPLags').hours time time2
*l(1/`MaxLPLags').logIP l(1/`MaxLPLags').logCPI 

local rhsOutput l(1/`MaxLPLags').FF l(1/`MaxLPLags').Output time time2
					    
****************************************************************
*** LP table Using Basic OLS
****************************************************************
						
forvalues v = 1/`o' { 
forvalues i=0/`horizon' {	
	
	* LP regression

	* WLI LP 
	newey WLI`i' RR `rhsWeeklyLaborIncome' if OCC == `v', lag(3)
				
	replace b_`v'WLI  = _b[RR] if _n == `i'+1
	replace se_`v'WLI = _se[RR] if _n == `i'+1
			
	* Real Wage LP
	newey RW`i' RR  `rhsRealWage' if OCC == `v', lag(3)
	
	replace b_`v'RW  = _b[RR] if _n == `i'+1
	replace se_`v'RW = _se[RR] if _n == `i'+1
	
	* Employment LP 
	newey Emp`i' RR `rhsEmp' if OCC == `v', lag(3)
				
	replace b_`v'Emp  = _b[RR] if _n == `i'+1
	replace se_`v'Emp = _se[RR] if _n == `i'+1
	
	* Hours LP 
	newey hours`i' RR `rhshours' if OCC == `v', lag(3)
				
	replace b_`v'hours  = _b[RR] if _n == `i'+1
	replace se_`v'hours = _se[RR] if _n == `i'+1
	
			}
}

forvalues i=0/`horizon' {	
	
	* LP regression

	* Output LP 
	newey Output`i' RR `rhsOutput' if OCC == 1, lag(3)
				
	replace b_Output  = _b[RR] if _n == `i'+1
	replace se_Output = _se[RR] if _n == `i'+1
	
			}


****************************************************************
*** Baseline OLS LP graphs
****************************************************************

gen Months = _n-1 if _n <= `horizon' +1

* zero line
gen zero = 0 if _n <= `horizon' +1


***** create confidence bands (in this case 90 and 95%) ****
	scalar sig1 = 0.05	 // specify significance level
	scalar sig2 = 0.3	 // specify significance level
	
	forvalues v = 1/`o' {

	gen up_`v'WLI = b_`v'WLI + invnormal(1-sig1/2)*se_`v'WLI if _n <= (`horizon' + 1)
	gen dn_`v'WLI = b_`v'WLI - invnormal(1-sig1/2)*se_`v'WLI if _n <= (`horizon' + 1)

	gen up2_`v'WLI = b_`v'WLI + invnormal(1-sig2/2)*se_`v'WLI if _n <= (`horizon' + 1)
	gen dn2_`v'WLI = b_`v'WLI - invnormal(1-sig2/2)*se_`v'WLI if _n <= (`horizon' + 1)
	
	gen up_`v'RW = b_`v'RW + invnormal(1-sig1/2)*se_`v'RW if _n <= (`horizon' + 1)
	gen dn_`v'RW = b_`v'RW - invnormal(1-sig1/2)*se_`v'RW if _n <= (`horizon' + 1)

	gen up2_`v'RW = b_`v'RW + invnormal(1-sig2/2)*se_`v'RW if _n <= (`horizon' + 1)
	gen dn2_`v'RW = b_`v'RW - invnormal(1-sig2/2)*se_`v'RW if _n <= (`horizon' + 1)
	
	gen up_`v'Emp = b_`v'Emp + invnormal(1-sig1/2)*se_`v'Emp if _n <= (`horizon' + 1)
	gen dn_`v'Emp = b_`v'Emp - invnormal(1-sig1/2)*se_`v'Emp if _n <= (`horizon' + 1)

	gen up2_`v'Emp = b_`v'Emp + invnormal(1-sig2/2)*se_`v'Emp if _n <= (`horizon' + 1)
	gen dn2_`v'Emp = b_`v'Emp - invnormal(1-sig2/2)*se_`v'Emp if _n <= (`horizon' + 1)
	
	gen up_`v'hours = b_`v'hours + invnormal(1-sig1/2)*se_`v'hours if _n <= (`horizon' + 1)
	gen dn_`v'hours = b_`v'hours - invnormal(1-sig1/2)*se_`v'hours if _n <= (`horizon' + 1)

	gen up2_`v'hours = b_`v'hours + invnormal(1-sig2/2)*se_`v'hours if _n <= (`horizon' + 1)
	gen dn2_`v'hours = b_`v'hours - invnormal(1-sig2/2)*se_`v'hours if _n <= (`horizon' + 1)

	}

	gen up2_Output = b_Output + invnormal(1-sig2/2)*se_Output if _n <= (`horizon' + 1)
	gen dn2_Output = b_Output - invnormal(1-sig2/2)*se_Output if _n <= (`horizon' + 1)

	

* Flip the impulse response functions to have a negative shock 

foreach var in WLI RW Emp hours {
	forvalues v = 1/`o' {
	
	replace b_`v'`var' = -.25*b_`v'`var'
	replace up_`v'`var' = -.25*up_`v'`var'
	replace dn_`v'`var' = -.25*dn_`v'`var'
	replace up2_`v'`var' = -.25*up2_`v'`var'
	replace dn2_`v'`var' = -.25*dn2_`v'`var'
	
	}
}


replace b_Output = .25*b_Output
replace up2_Output = .25*up2_Output
replace dn2_Output = .25*dn2_Output
	


save "${path}/Clean Data/Impulse Responses.dta", replace

************************ Impulse Response Functions *********************************

**********************
* Weekly Labor Income
**********************

twoway 	(line b_1WLI Months, lcolor(black) ///
	lpattern(solid) lwidth(medium)) /// 
	(line b_2WLI Months, lcolor(black) ///
	lpattern(solid) lwidth(medium)) /// 
	(line b_3WLI Months, lcolor(black) ///
	lpattern(solid) lwidth(medium)) /// 
	(line up2_3WLI Months, lcolor(gray) ///
	lpattern(dash) lwidth(medium)) ///
	(line dn2_3WLI Months, lcolor(gray) ///
	lpattern(dash) lwidth(medium)) ///
	(line up2_1WLI Months, lcolor(gray) ///
	lpattern(dash) lwidth(medium)) ///
	(line dn2_1WLI Months, lcolor(gray) ///
	lpattern(dash) lwidth(medium)) ///
	(line up2_2WLI Months, lcolor(gray) ///
	lpattern(dash) lwidth(medium)) ///
	(line dn2_2WLI Months, lcolor(gray) ///
	lpattern(dash) lwidth(medium)), ///
	ylabel(-0.03(.015).03) ytitle("Log Total Weekly Labor Income", size(medsmall)) xtitle("Months", size(medsmall)) ///
	graphregion(color(white)) plotregion(color(white)) text(.019 37 "Abstract", color(black) size(medsmall)) ///
	text(-.014 38 "Routine", color(black) size(medsmall)) text(.004 38 "Manual", color(black) size(medsmall)) ///
	name(WLI, replace) legend(off)
	graph save "${path}\Results\WLI.gph", replace
	
************
* Real Wage	
************

*
twoway 	(line b_1RW Months, lcolor(black) ///
	lpattern(solid) lwidth(medium)) /// 
	(line b_2RW Months, lcolor(black) ///
	lpattern(solid) lwidth(medium)) /// 
	(line b_3RW Months, lcolor(black) ///
	lpattern(solid) lwidth(medium)) ///
	(line up2_3RW Months, lcolor(gray) ///
	lpattern(dash) lwidth(medium)) ///
	(line dn2_3RW Months, lcolor(gray) ///
	lpattern(dash) lwidth(medium)) ///
	(line up2_1RW Months, lcolor(gray) ///
	lpattern(dash) lwidth(medium)) ///
	(line dn2_1RW Months, lcolor(gray) ///
	lpattern(dash) lwidth(medium)) ///
	(line up2_2RW Months, lcolor(gray) ///
	lpattern(dash) lwidth(medium)) ///
	(line dn2_2RW Months, lcolor(gray) ///
	lpattern(dash) lwidth(medium)), ///
	ylabel(-0.03(.015).03) title("B") ytitle("Log Average Real Wage", size(medsmall)) xtitle("Months", size(medsmall)) ///
	graphregion(color(white)) plotregion(color(white)) text(.01 29 "Abstract", color(black) size(medsmall)) ///
	text(-.004 38 "Routine", color(black) size(medsmall)) text(.004 38.5 "Manual", color(black) size(medsmall)) ///
	name(RW, replace) legend(off)
	graph save "${path}\Results\RealWage.gph", replace
	

  ***********
  *Employment
  ***********
  
  *

twoway 	(line b_1Emp Months, lcolor(black) ///
	lpattern(solid) lwidth(medium)) /// 
	(line b_2Emp Months, lcolor(black) ///
	lpattern(solid) lwidth(medium)) /// 
	(line b_3Emp Months, lcolor(black) ///
	lpattern(solid) lwidth(medium)) ///
	(line up2_3Emp Months, lcolor(gray) ///
	lpattern(dash) lwidth(medium)) ///
	(line dn2_3Emp Months, lcolor(gray) ///
	lpattern(dash) lwidth(medium)) ///
	(line up2_1Emp Months, lcolor(gray) ///
	lpattern(dash) lwidth(medium)) ///
	(line dn2_1Emp Months, lcolor(gray) ///
	lpattern(dash) lwidth(medium)) ///
	(line up2_2Emp Months, lcolor(gray) ///
	lpattern(dash) lwidth(medium)) ///
	(line dn2_2Emp Months, lcolor(gray) ///
	lpattern(dash) lwidth(medium)), ///
	ylabel(-0.03(.015).03) title("A") ytitle("Log Total Employment", size(medsmall)) xtitle("Months", size(medsmall)) graphregion(color(white)) plotregion(color(white)) text(.015 38 "Abstract", color(black) size(medsmall)) ///
	text(-.01 38 "Routine", color(black) size(medsmall)) text(.001 38 "Manual", color(black) size(medsmall)) ///
	name(EMP, replace) legend(off)
	graph save "${path}\Results\Employment.gph", replace
	
	
****************************************************************************
* By Industry
****************************************************************************

*
  
use "${path}\Clean Data\CPS Final Ind.dta", clear


rename WeeklyLaborIncome WLI
rename RealWage RW
rename Emp EMP


xtset OCC4 time
drop RR
rename resid_garch RR

egen t = min(time)
gen time2 = time*time

*******************
* Levels
*******************

replace RW = log(RW)
replace WLI = log(WLI)
gen Emp = log(emp)


***** variables to store the impulse response (vector of betas from the LP regressions) and standard errors

*********************
* Define local macros
*********************

* number of lags
local MaxLPLags 12

* horizon
local horizon 36

* Romer shocks or Fed Funds instrumented for with Romer shocks
* (Change this depending on whether you're running OLS with RR or IV with FF)
local policy RR

* O is the number of occupation subgroups under consideration
local o 6

***** LHS variable: the response variable

forvalues i=0/`horizon' {
	
	gen RW`i'    = f`i'.RW - l1.RW
	gen WLI`i'   = f`i'.WLI -l1.WLI
	gen Emp`i'   = f`i'.Emp - l1.Emp
	gen Hours`i' = f`i'.Hours - l1.Hours
	
}

forvalues v = 1/`o' {
gen b_`v'WLI=.
gen b_`v'RW=.
gen b_`v'Emp=.
gen b_`v'Hours=.

gen se_`v'WLI=.
gen se_`v'RW=.
gen se_`v'Emp=.
gen se_`v'Hours=.

}

** Controls in LP regression **

local rhsWeeklyLaborIncome l(1/`MaxLPLags').FF l(1/`MaxLPLags').WLI time time2
*l(1/`MaxLPLags').logIP l(1/`MaxLPLags').logCPI 
*l(1/`MaxLPLags').UE
						
local rhsRealWage l(1/`MaxLPLags').FF l(1/`MaxLPLags').RW time time2
*l(1/`MaxLPLags').logIP l(1/`MaxLPLags').logCPI 
*l(1/`MaxLPLags').UE	
					
local rhsEmp 	 l(1/`MaxLPLags').FF l(1/`MaxLPLags').Emp time time2
*l(1/`MaxLPLags').logIP l(1/`MaxLPLags').logCPI 
*l(1/`MaxLPLags').UE				   
						
* exclude contemporaneous lag of impulse (short term rate) and response (Hours)
local rhsHours   l(1/`MaxLPLags').FF l(1/`MaxLPLags').Hours time time2
*l(1/`MaxLPLags').logIP l(1/`MaxLPLags').logCPI 
*l(1/`MaxLPLags').UE
					    
****************************************************************
*** LP table Using Basic OLS
****************************************************************
						
forvalues v = 1/`o' { 
forvalues i=0/`horizon' {	
	
	* LP regression

	* WLI LP 
	newey WLI`i' RR `rhsWeeklyLaborIncome' if OCC == `v', lag(3)
				
	replace b_`v'WLI  = _b[RR] if _n == `i'+1
	replace se_`v'WLI = _se[RR] if _n == `i'+1
			
	* Real Wage LP
	newey RW`i' RR  `rhsRealWage' if OCC == `v', lag(3)
	
	replace b_`v'RW  = _b[RR] if _n == `i'+1
	replace se_`v'RW = _se[RR] if _n == `i'+1
	
	* Employment LP 
	newey Emp`i' RR `rhsEmp' if OCC == `v', lag(3)
				
	replace b_`v'Emp  = _b[RR] if _n == `i'+1
	replace se_`v'Emp = _se[RR] if _n == `i'+1
	
	* Unemp LP 
	newey Hours`i' RR `rhsHours' if OCC == 1, lag(3)
				
	replace b_`v'Hours  = _b[RR] if _n == `i'+1
	replace se_`v'Hours = _se[RR] if _n == `i'+1
	

			}
}


****************************************************************
*** Baseline OLS LP graphs
/****************************************************************/

gen Months = _n-1 if _n <= `horizon' +1

* zero line
gen zero = 0 if _n <= `horizon' +1


***** create confidence bands (in this case 90 and 95%) ****
	scalar sig1 = 0.05	 // specify significance level
	scalar sig2 = 0.3	 // specify significance level
	
	forvalues v = 1/`o' {

	gen up_`v'WLI = b_`v'WLI + invnormal(1-sig1/2)*se_`v'WLI if _n <= (`horizon' + 1)
	gen dn_`v'WLI = b_`v'WLI - invnormal(1-sig1/2)*se_`v'WLI if _n <= (`horizon' + 1)

	gen up2_`v'WLI = b_`v'WLI + invnormal(1-sig2/2)*se_`v'WLI if _n <= (`horizon' + 1)
	gen dn2_`v'WLI = b_`v'WLI - invnormal(1-sig2/2)*se_`v'WLI if _n <= (`horizon' + 1)
	
	gen up_`v'RW = b_`v'RW + invnormal(1-sig1/2)*se_`v'RW if _n <= (`horizon' + 1)
	gen dn_`v'RW = b_`v'RW - invnormal(1-sig1/2)*se_`v'RW if _n <= (`horizon' + 1)

	gen up2_`v'RW = b_`v'RW + invnormal(1-sig2/2)*se_`v'RW if _n <= (`horizon' + 1)
	gen dn2_`v'RW = b_`v'RW - invnormal(1-sig2/2)*se_`v'RW if _n <= (`horizon' + 1)
	
	gen up_`v'Emp = b_`v'Emp + invnormal(1-sig1/2)*se_`v'Emp if _n <= (`horizon' + 1)
	gen dn_`v'Emp = b_`v'Emp - invnormal(1-sig1/2)*se_`v'Emp if _n <= (`horizon' + 1)

	gen up2_`v'Emp = b_`v'Emp + invnormal(1-sig2/2)*se_`v'Emp if _n <= (`horizon' + 1)
	gen dn2_`v'Emp = b_`v'Emp - invnormal(1-sig2/2)*se_`v'Emp if _n <= (`horizon' + 1)
	
	gen up_`v'Hours = b_`v'Hours + invnormal(1-sig1/2)*se_`v'Hours if _n <= (`horizon' + 1)
	gen dn_`v'Hours = b_`v'Hours - invnormal(1-sig1/2)*se_`v'Hours if _n <= (`horizon' + 1)

	gen up2_`v'Hours = b_`v'Hours + invnormal(1-sig2/2)*se_`v'Hours if _n <= (`horizon' + 1)
	gen dn2_`v'Hours = b_`v'Hours - invnormal(1-sig2/2)*se_`v'Hours if _n <= (`horizon' + 1)

	}


* Flip the impulse response functions to have a negative shock 

foreach var in WLI RW Emp Hours {
	forvalues v = 1/`o' {
	
	replace b_`v'`var' = -.25*b_`v'`var'
	replace up_`v'`var' = -.25*up_`v'`var'
	replace dn_`v'`var' = -.25*dn_`v'`var'
	replace up2_`v'`var' = -.25*up2_`v'`var'
	replace dn2_`v'`var' = -.25*dn2_`v'`var'
	
	}
}

label variable b_1WLI "Less Responsive"
label variable b_4WLI "More Responsive"
label variable b_5WLI "Routine"
label variable b_6WLI "Abstract"


twoway 	(line b_1WLI Months, lcolor(black) ///
	lpattern(solid) lwidth(med)) /// 
	(line b_4WLI Months, lcolor(black) ///
	lpattern(dash) lwidth(med)) ///
	(scatter b_3WLI Months, mlcolor(black) mfcolor(black)) ///
	(scatter b_2WLI Months, mlcolor(black) mfcolor(none)) ///
	(line b_2WLI Months, lcolor(black) ///
	lpattern(solid) lwidth(med)) /// 
	(line b_3WLI Months, lcolor(black) ///
	lpattern(solid) lwidth(med)) ///
	(scatter b_6WLI Months, mlcolor(black) mfcolor(black)) ///
	(scatter b_5WLI Months, mlcolor(black) mfcolor(none)) ///
	(line b_5WLI Months, lcolor(black) ///
	lpattern(dash) lwidth(med)) ///
	(line b_6WLI Months, lcolor(black) ///
	lpattern(dash) lwidth(med)), ///
	 ylabel(-0.04(.015).04) ytitle("Log Total Weekly Labor Income", size(medsmall)) xtitle("Months", size(medsmall)) ///
	graphregion(color(white)) plotregion(color(white)) legend(ring(0) order(1 "Less Responsive" 2 "More Responsive" 3 "Abstract" 4 "Routine") size(small) ) ///
	name(MLIind, replace)
	graph save "${path}\Results\WLI_ind.gph", replace
	
	
	
*	
twoway 	(line b_1Emp Months, lcolor(black) ///
	lpattern(solid) lwidth(med)) /// 
	(line b_2Emp Months, lcolor(black) ///
	lpattern(solid) lwidth(med)) /// 
	(line b_3Emp Months, lcolor(black) ///
	lpattern(solid) lwidth(med)) ///
	(line b_4Emp Months, lcolor(black) ///
	lpattern(dash) lwidth(med)) ///
	(line b_5Emp Months, lcolor(black) ///
	lpattern(dash) lwidth(med)) ///
	(line b_6Emp Months, lcolor(black) ///
	lpattern(dash) lwidth(med)), ///
	title("Impulse Response of Log Employment to -25 bp Shock", color(black) size(medium)) ///
	ylabel(-0.03(.025).05) ytitle("Log Total Employment", size(medsmall)) xtitle("Months", size(medsmall)) ///
	graphregion(color(white)) plotregion(color(white)) text(.04 32 "Abstract: Responsive Capital", color(green) size(small)) ///
	text(-.027 32 "Routine: Responsive Capital", color(navy) size(small)) text(-.015 33 "Routine: Unresponsive Capital", color(emidblue) size(small)) ///
	text(.017 34 "Abstract: Unresponsive Capital", color(teal) size(small)) text(0.005 34 "Manual: Responsive Capital", size(small)) ///
	text(-.005 34 "Manual: Unresponsive Capital", size(small)) legend(off) ///
	name(Empind, replace)
	graph save "${path}\Results\Employment_ind.gph", replace
	